﻿//value为空的处理，同时计算准确样本和有效数据样本个数
function nullValueTransferCount(value, effectCountArr, accuracyCountArr, index) {
    if (value == null) {
        return "--";
    }
    else {
        effectCountArr[index] = effectCountArr[index] + 1;
        if (value == 0) {
            accuracyCountArr[index] = accuracyCountArr[index] + 1;
        }
        return value;
    }
}
//首要污染物准确性表示，同时计算准确样本和有效数据样本个数
function primarryPollutantAccuracyTransferCount(value, effectCountArr, accuracyCountArr, index) {
    if (value == null) {
        return "--";
    }
    else {
        effectCountArr[index] = effectCountArr[index] + 1;
        if (value == 0) {
            accuracyCountArr[index] = accuracyCountArr[index] + 1;
        }
        var html;
        if (value == 0) {
            var html = "<span style='color:green;font-weight:bold;font-size:14px;'>√</span>";
        }
        else {
            var html = "<span>×</span>";
        }
        return html;

    }
}
//value为空的处理
function nullPrimarryPollutantTransfer(value) {
    if (value == null) {
        return "--";
    }
    else if (value == "—") {
        return "无首要污染物";
    }
    else {
        return value;
    }
}
function null2ValueTransfer(value1, value2) {
    if (value1 == null || value1 == "-99" || value2 == null || value2 == "-99") {
        return "--";
    }
    else {
        return value1 + "~" + value2;
    }
}

//计算准确率
function accuracyPercetage(accuracyCount, effectCount) {
    var rate;
    if (effectCount != 0) {
        var temp = accuracyCount * 100 / effectCount;
        rate = Number(temp.toFixed(0));
        return rate + "%";
    }
    else {
        return "--";
    }
}
function accuracyPercentageNew(jsonData,pollutantName) {
    var relativeAvgs = [];
    var RelativeError=pollutantName+"_RelativeError";
    if (jsonData.length > 0) {
        var d = jsonData;
        var relativeValueInInForecastModel0 = 0;
        var relativeValueInInForecastModel0Count = 0;
        var relativeValueInInForecastModel1 = 0;
        var relativeValueInInForecastModel1Count = 0;
        var relativeValueInInForecastModel2 = 0;
        var relativeValueInInForecastModel2Count = 0;
        var relativeValueInInForecastModel3 = 0;
        var relativeValueInInForecastModel3Count = 0;
        var relativeValueInInForecastModel5 = 0;
        var relativeValueInInForecastModel5Count = 0;
        for (var i = 0; i < d.length; i++) {
            var temp = d[i];
            if (d[i].ForecastModelId==0) {
                relativeValueInInForecastModel0 += d[i][RelativeError];
                relativeValueInInForecastModel0Count++;
            }
            if (d[i].ForecastModelId == 1) {
                relativeValueInInForecastModel1 += d[i][RelativeError];
                relativeValueInInForecastModel1Count++;
            }
            if (d[i].ForecastModelId == 2) {
                relativeValueInInForecastModel2 += d[i][RelativeError];
                relativeValueInInForecastModel2Count++;
            }
            if (d[i].ForecastModelId == 3) {
                relativeValueInInForecastModel3 += d[i][RelativeError];
                relativeValueInInForecastModel3Count++;
            }
            if (d[i].ForecastModelId == 5) {
                relativeValueInInForecastModel5 += d[i][RelativeError];
                relativeValueInInForecastModel5Count++;
            }
        }
        var model0 = (1 - relativeValueInInForecastModel0 / relativeValueInInForecastModel0Count) * 100;
        var model1 = (1 - relativeValueInInForecastModel1 / relativeValueInInForecastModel1Count) * 100;
        var model2 = (1 - relativeValueInInForecastModel2 / relativeValueInInForecastModel2Count) * 100;
        var model3 = (1 - relativeValueInInForecastModel3 / relativeValueInInForecastModel3Count) * 100;
        var model5 = (1 - relativeValueInInForecastModel5 / relativeValueInInForecastModel5Count) * 100;

        relativeAvgs.push(Number(model0.toFixed(1)) + "%");
        relativeAvgs.push(Number(model1.toFixed(1)) + "%");
        relativeAvgs.push(Number(model2.toFixed(1)) + "%");
        relativeAvgs.push(Number(model3.toFixed(1)) + "%");
        relativeAvgs.push(Number(model5.toFixed(1)) + "%");
    }
    return relativeAvgs;
}


function accuracyPercentage(jsonData) {
    var relativeAvgs = [];
    if (jsonData.length > 0) {
        var d = jsonData;
        var relativeValueInInForecastModel0 = 0;
        var relativeValueInInForecastModel0Count = 0;
        var relativeValueInInForecastModel1 = 0;
        var relativeValueInInForecastModel1Count = 0;
        var relativeValueInInForecastModel2 = 0;
        var relativeValueInInForecastModel2Count = 0;
        var relativeValueInInForecastModel3 = 0;
        var relativeValueInInForecastModel3Count = 0;
        var relativeValueInInForecastModel5 = 0;
        var relativeValueInInForecastModel5Count = 0;
        for (var i = 0; i < jsonData.length; i++) {          
            if (d[i].RelativeValueInInForecastModel0 != null) {
                relativeValueInInForecastModel0 += d[i].RelativeValueInInForecastModel0;
                relativeValueInInForecastModel0Count++;
            }
            if (d[i].RelativeValueInInForecastModel1 != null) {
                relativeValueInInForecastModel1 += d[i].RelativeValueInInForecastModel1;
                relativeValueInInForecastModel1Count++;
            }
            if (d[i].RelativeValueInInForecastModel2 != null) {
                relativeValueInInForecastModel2 += d[i].RelativeValueInInForecastModel2;
                relativeValueInInForecastModel2Count++;
            }
            if (d[i].RelativeValueInInForecastModel3 != null) {
                relativeValueInInForecastModel3 += d[i].RelativeValueInInForecastModel3;
                relativeValueInInForecastModel3Count++;
            }
            if (d[i].RelativeValueInInForecastModel5 != null) {
                relativeValueInInForecastModel5 += d[i].RelativeValueInInForecastModel5;
                relativeValueInInForecastModel5Count++;
            }
        }

        var model0 = (1 - relativeValueInInForecastModel0 / relativeValueInInForecastModel0Count) * 100;
        var model1 = (1 - relativeValueInInForecastModel1 / relativeValueInInForecastModel1Count) * 100;
        var model2 = (1 - relativeValueInInForecastModel2 / relativeValueInInForecastModel2Count) * 100;
        var model3 = (1 - relativeValueInInForecastModel3 / relativeValueInInForecastModel3Count) * 100;
        var model5 = (1 - relativeValueInInForecastModel5 / relativeValueInInForecastModel5Count) * 100;

        relativeAvgs.push(Number(model0.toFixed(1)) + "%");
        relativeAvgs.push(Number(model1.toFixed(1)) + "%");
        relativeAvgs.push(Number(model2.toFixed(1)) + "%");
        relativeAvgs.push(Number(model3.toFixed(1)) + "%");
        relativeAvgs.push(Number(model5.toFixed(1)) + "%");
    }
    return relativeAvgs;
}
